package dxunderground.utilities.math;

public class Random {
	/**
	 * @param max
	 *            Maximum value that is to be returned
	 * @return a random value between 0 and max
	 */
	public static int randomCap(int max) {
		int scale = (int) Math.pow(10, (max + "").length());
		int num = (int) (Math.random() * scale);
		while (num > max) {
			num = (int) (Math.random() * scale);
		}
		return num;
	}

	public static int[] randomCapArray(int max, int size) {
		int[] ret = new int[size];

		for (int i = 0; i < size; i++)
			ret[i] = randomCap(max);

		return ret;
	}

	public static void main(String[] args) {
		int size = 1000;
		int max = 10;
		int[] num = new int[size];
		int[] total = new int[max + 1];
		int totalGen = 0;

		for (int i = 0; i < size; i++) {
			num[i] = Random.randomCap(max);
		}
		for (int i = 0; i < size; i++) {
			for (int j = 0; j < max + 1; j++) {
				if (num[i] == j) {
					total[j]++;
				}
			}

		}
		for (int j = 0; j < max + 1; j++) {
			System.out.println(j + ": " + total[j] + "\t" + (double) total[j] / size * 100 + "%");
			totalGen += total[j];
		}
	}
}
